/**
 * Copyright by e-shion.net
 */
package net.xfok.ui.dock;

import net.xfok.ui.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 * @author 2011-1-18 Howard
 * 
 */
public class Dock extends Activity implements OnTouchListener{
	private static final String TAG = "Dock";
	private static final int NOR_SIZE=45;
	private static final int MID_SIZE=(int)(NOR_SIZE*1.2);
	private static final int BIG_SIZE=(int)(NOR_SIZE*1.5);
	private static final boolean ANIM=false;
	
	private ImageView btHome, btMedia, btEbook, btMsg, btBrowser;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dock);
		setViews();
	}

	private void setViews() {
		btHome = (ImageView) findViewById(R.id.bt_home);
		btHome.setBackgroundColor(Color.TRANSPARENT);
		btHome.setOnClickListener(new DockClick());
		btHome.setOnTouchListener(this);
		btMedia = (ImageView) findViewById(R.id.bt_media);
		btMedia.setBackgroundColor(Color.TRANSPARENT);
		btMedia.setOnClickListener(new DockClick());
		btMedia.setOnTouchListener(this);
		btEbook = (ImageView) findViewById(R.id.bt_ebook);
		btEbook.setBackgroundColor(Color.TRANSPARENT);
		btEbook.setOnClickListener(new DockClick());
		btEbook.setOnTouchListener(this);
		btMsg = (ImageView) findViewById(R.id.bt_msg);
		btMsg.setBackgroundColor(Color.TRANSPARENT);
		btMsg.setOnClickListener(new DockClick());
		btMsg.setOnTouchListener(this);
		btBrowser = (ImageView) findViewById(R.id.bt_browser);
		btBrowser.setBackgroundColor(Color.TRANSPARENT);
		btBrowser.setOnClickListener(new DockClick());
		btBrowser.setOnTouchListener(this);
		small2Big(btHome,ANIM);
		small2Mid(btMedia, ANIM);
	}
	
	private void small2Big(View view , boolean anim){
		small2Mid(view,anim);
		mid2Big(view,anim);
	}
	
	private void big2Small(View view , boolean anim ){
		big2Mid(view,anim);
		mid2Small(view,anim);
	}
	
	private void small2Mid(View view , boolean anim){
		if(anim){
			Animation animation=AnimationUtils.loadAnimation(this, R.anim.small2mid);
			view.startAnimation(animation);
		}
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(MID_SIZE, MID_SIZE);
		view.setLayoutParams(layoutParams);
	}
	
	private void mid2Big(View view , boolean anim){
		if(anim){
			Animation animation=AnimationUtils.loadAnimation(this, R.anim.mid2big);
			view.startAnimation(animation);
		}
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(BIG_SIZE, BIG_SIZE);
		view.setLayoutParams(layoutParams);
	}
	
	private void big2Mid(View view , boolean anim){
		if(anim){
			Animation animation=AnimationUtils.loadAnimation(this, R.anim.big2mid);
			view.startAnimation(animation);
		}
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(MID_SIZE, MID_SIZE);
		view.setLayoutParams(layoutParams);
	}
	
	private void mid2Small(View view , boolean anim){
		if(anim){
			Animation animation=AnimationUtils.loadAnimation(this, R.anim.mid2small);
			view.startAnimation(animation);
		}
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(NOR_SIZE, NOR_SIZE);
		view.setLayoutParams(layoutParams);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		return false;
	}

	private class DockClick implements OnClickListener{

		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.bt_home:
					small2Big(btHome,ANIM);
					small2Mid(btMedia,ANIM);
					break;
				case R.id.bt_media:
					small2Big(btMedia,ANIM);
					small2Mid(btHome,ANIM);
					small2Mid(btEbook,ANIM);
					break;
				case R.id.bt_ebook:
					small2Big(btEbook,ANIM);
					small2Mid(btMedia,ANIM);
					small2Mid(btMsg,ANIM);
					break;
				case R.id.bt_msg:
					small2Big(btMsg,ANIM);
					small2Mid(btBrowser,ANIM);
					small2Mid(btEbook,ANIM);
					break;
				case R.id.bt_browser:
					small2Big(btBrowser,ANIM);
					small2Mid(btMsg,ANIM);
					break;
			default:
				break;
			}
			
		}
		
	}
	

}
